<template>
  <Api :input="model" :ok="createOrUpdate" ok-msg="保存成功" @ok="Modal.ok()">
    <template #default="{ input, onOk, loading, submitting }">
      <Form :data="input" @ok="onOk" :loading="loading" :mode="mode">
        <FormItem field="username" title="用户名" required>
          <Input v-model="input.username" />
        </FormItem>
        <FormItem field="mobile" title="手机">
          <Input v-model="input.mobile" />
        </FormItem>
        <FormItem field="email" title="Email">
          <Input v-model="input.email" />
        </FormItem>
        <FormItem field="nickname" title="昵称">
          <Input v-model="input.nickname" />
        </FormItem>
        <FormItem field="name" title="姓名">
          <Input v-model="input.name" />
        </FormItem>
        <FormItem field="gender" title="性别" format="Enum" params="Gender">
          <Enum clazz="Gender" v-model="input.gender" />
        </FormItem>
        <template #op>
          <ModalButton :loading="submitting" />
        </template>
      </Form>
    </template>
  </Api>
</template>

<script setup lang="ts">
import { Enum, Form, FormItem, Input, Modal, Button, ModalButton } from '@idmy/ui'
import { createOrUpdate } from './services'
import { Api } from '@idmy/core'

defineProps({ model: Object, mode: String })
</script>
